package com.personal.cuncunxing.util;

import android.content.Context;
import android.util.Base64;
import android.util.Log;

import com.personal.cuncunxing.common.OkHttpUtils;
import com.personal.cuncunxing.common.ResultCallback;
import com.personal.cuncunxing.module.home.pojo.Info;

import org.jsoup.Connection;
import org.jsoup.Connection.Method;
import org.jsoup.Connection.Response;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import java.io.IOException;
import java.util.Map;

import okhttp3.Request;

/**
 * Description: 采用jsoup爬取电影网站资源
 * Created by kode on 2020/5/31.
 */
public final class JsoupUtils {
    private static final String TAG = "JsoupUtils";

    //第一次访问获取的cookie(查看发现就返回一个cookie:ASP.NET_SessionId)
    private Map<String, String> cookies = null;

    //__ViewState 用于验证的信息
    private String viewState = null;


    private static class HolderClass {
        private final static JsoupUtils instance = new JsoupUtils();
    }

    public static JsoupUtils getInstance() {
        return JsoupUtils.HolderClass.instance;
    }

    /***
     * 获取网站主页信息
     * @param url
     */
    public Document getHomeInfo(String url, Context context) {
        return null;
    }

    /**
     * 获取_ViewState
     *
     * @return
     */
    public String getViewState(String htmlContent) {
        Document document = Jsoup.parse(htmlContent);
        Log.d(TAG, "getViewState: " + document);
        Element ele = document.getElementsByTag("input").get(0);
        String value = ele.attr("value");
        //System.out.println("_ViewState:" + value);
        Log.d(TAG, "getViewState: " + value);
        // 获取到viewState
        this.viewState = value;
        return value;
    }
}
